
from lib.api import *
import re
from lib.urls import *


def suite_setup():
    INFO('返回token')
    global auth_token
    auth_token = am.getToken()




class API_3001:
    name = 'API_3001'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token正确，deviceName正确，locationId不填，startTime正确，status正确")
        urlpara = {
            'deviceName':'ESCALATOR003',
            'startTime':'2021-06-08 22:22:22',
            'status':'0'
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[14][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3002:
    name = 'API_3002'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token过期，deviceName正确，locationId不填，startTime正确，status正确")
        urlpara = {
            'deviceName':'ESCALATOR003',
            'startTime':'2021-06-08 22:22:22',
            'status':0
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlS2V5IjoiIiwidXNlck5hbWUiOiJ5enlhZG1pbiIsImV4cCI6MTYyMjAwNjg2NCwidXNlcklkIjoieXp5YWRtaW4ifQ.-fJYSIJdfbiSabU71x9nbb2n2qbl8IM_s6xk0LuNVfk'
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[15][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])

class API_3003:
    name = 'API_3003'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token 为空，deviceName正确，locationId不填，startTime正确，status正确")
        urlpara = {
            'deviceName':'ESCALATOR003',
            'startTime':'2021-06-08 22:22:22',
            'status':'0'
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 # headers={
                                 #     "auth-token": auth_token
                                 # },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[15][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3004:
    name = 'API_3004'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token正确，deviceName正确，locationId：349 正确，startTime正确，status正确")
        urlpara = {
            'deviceName':'ESCALATOR003',
            'startTime':'2021-06-08 22:22:22',
            'status':'0',
            'locationId':349
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[14][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3005:
    name = 'API_3005'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token正确，deviceName正确，startTime正确，status正确，locationId：347 错误，347虽然存在，但不是目标location")
        urlpara = {
            'deviceName':'ESCALATOR003',
            'startTime':'2021-06-08 22:22:22',
            'status':'0',
            'locationId':347
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[15][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3006:
    name = 'API_3006'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token正确，deviceName：ES003错误，locationId不填，startTime正确，status正确")
        urlpara = {
            'deviceName':'ES003',
            'startTime':'2021-06-08 22:22:22',
            'status':'0'
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[15][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3007:
    name = 'API_3007'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token正确，deviceName 为空，locationId不填，startTime正确，status正确")
        urlpara = {
            # 'deviceName':'ESCALATOR003',
            'startTime':'2021-06-08 22:22:22',
            'status':'0'
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[15][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])

class API_3008:
    name = 'API_3008'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token正确，deviceName正确，locationId不填，startTime正确，status：0 正确")
        urlpara = {
            'deviceName':'ESCALATOR003',
            'startTime':'2021-06-08 22:22:22',
            'status':'0'
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[14][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3009:
    name = 'API_3009'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token正确，deviceName正确，locationId不填，startTime正确，status：1 正确")
        urlpara = {
            'deviceName':'ESCALATOR003',
            'startTime':'2021-06-08 22:22:22',
            'status':'1'
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[14][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3010:
    name = 'API_3010'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token正确，deviceName正确，locationId不填，startTime：2021.06.08 22:22:22 错误，status正确")
        urlpara = {
            'deviceName':'ESCALATOR003',
            'startTime':'2021.06.08 22:22:22',
            'status':'0'
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[15][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3011:
    name = 'API_3011'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token正确，deviceName正确，locationId不填，startTime：2021-06-08 22：22：22 错误，status正确")
        urlpara = {
            'deviceName':'ESCALATOR003',
            'startTime':'2021-06-08 22：22：22',
            'status':'0'
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[15][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3012:
    name = 'API_3012'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token正确，deviceName正确，locationId不填，startTime：2021-6-8 22：22：22 错误，status正确")
        urlpara = {
            'deviceName':'ESCALATOR003',
            'startTime':'2021-6-8 22：22：22',
            'status':'0'
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[15][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3013:
    name = 'API_3013'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token正确，deviceName正确，locationId不填，startTime：2021-06-01 22:22:22 错误，status正确")
        urlpara = {
            'deviceName':'ESCALATOR003',
            'startTime':'2021-06-01 22:22:22',
            'status':'0'
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[15][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])



class API_3013_01:
    name = 'API_3013_01'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token正确，deviceName正确，locationId不填，startTime：2021-06-01 22:22:19hkkkkkk 错误，status正确")
        urlpara = {
            'deviceName':'ESCALATOR003',
            'startTime':'2021-06-01 22:22:19hkkkkkk',
            'status':'0'
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[15][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])



class API_3013_02:
    name = 'API_3013_02'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token正确，deviceName正确，locationId不填，startTime：2021-06-01 2:2:1 错误，status正确")
        urlpara = {
            'deviceName':'ESCALATOR003',
            'startTime':'2021-06-01 2:2:1',
            'status':'0'
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[15][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])



class API_3014:
    name = 'API_3014'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token正确，deviceName正确，locationId不填，startTime 为空，status正确")
        urlpara = {
            'deviceName':'ESCALATOR003',
            # 'startTime':'2021-06-01 22:22:22',
            'status':'0'
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[15][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3015:
    name = 'API_3015'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token正确，deviceName正确，locationId不填，startTime正确，status：2 错误")
        urlpara = {
            'deviceName':'ESCALATOR003',
            'startTime':'2021-06-08 22:22:22',
            'status':2
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[15][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3016:
    name = 'API_3016'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token正确，deviceName正确，locationId不填，startTime正确，status 为空")
        urlpara = {
            'deviceName':'ESCALATOR003',
            'startTime':'2021-06-08 22:22:22'
            # 'status':2
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[15][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])
